package com.biyao.service.model.base.imp;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import java.util.HashMap;
import java.util.Map;

import com.biyao.schedulingdao.base.TRollerTypeMapper;
import com.biyao.schedulingentity.base.TRollerMaterialEntity;
import com.biyao.schedulingentity.base.TRollerTypeEntity;
import com.biyao.service.model.base.TRollerTypeMessage;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.ArrayList;
/**
 * 
 *
 * @author code generator
 * @date 2019-09-16 09:44:09
 */
@Service
public class TRollerTypeService extends ServiceImpl<TRollerTypeMapper, TRollerTypeEntity> implements TRollerTypeMessage {

    public Page list(int pageNum, int pageSize){

        EntityWrapper<TRollerTypeEntity> tRollerTypeentityWrapper=new EntityWrapper<>();
        Page page=selectPage(new Page(pageNum,pageSize),tRollerTypeentityWrapper);
        page.setRecords(formatRecords(page.getRecords()));
        return page;
    }

    List formatRecords(List<TRollerTypeEntity> list){
        List resList=new ArrayList();
        for(TRollerTypeEntity tRollerTypeEntity:list){
            Map map=formatEntity(tRollerTypeEntity);
            resList.add(map);
        }
        return resList;
    }

    Map formatEntity(TRollerTypeEntity tRollerTypeEntity){
        Map map=new HashMap(16);
        //轧辊类型
        if(tRollerTypeEntity.getId()!=null){
           map.put("id",tRollerTypeEntity.getId());
        }
        //类型代号
        if(tRollerTypeEntity.getCode()!=null){
           map.put("code",tRollerTypeEntity.getCode());
        }
        //类型名称
        if(tRollerTypeEntity.getName()!=null){
           map.put("name",tRollerTypeEntity.getName());
        }
        //
        if(tRollerTypeEntity.getRemark()!=null){
           map.put("remark",tRollerTypeEntity.getRemark());
        }
        //
        if(tRollerTypeEntity.getCreateTime()!=null){
           map.put("createTime",tRollerTypeEntity.getCreateTime());
        }
        //
        if(tRollerTypeEntity.getUpdateTime()!=null){
           map.put("updateTime",tRollerTypeEntity.getUpdateTime());
        }
        //
        if(tRollerTypeEntity.getCreateBy()!=null){
           map.put("createBy",tRollerTypeEntity.getCreateBy());
        }
        //
        if(tRollerTypeEntity.getUpdateBy()!=null){
           map.put("updateBy",tRollerTypeEntity.getUpdateBy());
        }
        return map;
    }

    @Override
    public TRollerTypeEntity selectTRollerTypeById(Integer id) {
        if(id!=null){
            return selectById(id);
        }
        return null;
    }

    public Boolean selectCodeIsRepeat(String code) {
        EntityWrapper<TRollerTypeEntity> tRollerMaterialEntityEntityWrapper=new EntityWrapper<>();
        tRollerMaterialEntityEntityWrapper.eq("code",code);
        List<TRollerTypeEntity> list=selectList(tRollerMaterialEntityEntityWrapper);
        if(list.size()>0){
            return true;
        }
        return false;
    }

    public Boolean selectUpdateCodeIsRepeat(String code,Integer id) {
        EntityWrapper<TRollerTypeEntity> tRollerMaterialEntityEntityWrapper=new EntityWrapper<>();
        tRollerMaterialEntityEntityWrapper.eq("code",code);
        List<TRollerTypeEntity> list=selectList(tRollerMaterialEntityEntityWrapper);
        if(list.size()>0){
            if(list.get(0).getId().intValue()!=id.intValue()){
                return true;
            }
            return false;
        }
        return false;
    }
}

